import os
import sys
import time


from bcc import BPF

from Main_Test_Util import generate_test_database, generate_random_database
from main_util import start_access_control, set_test_database, set_database_by_policy_file
from python_part.BPFBackend import BPFBackend
from python_part.BPFMapLoader import BPFMapLoader
from python_part.PolicyStoreModule import PolicyStoreModule

from GlobaLogger import Log
log = Log(__name__).getlog()

if __name__ == '__main__':
    policy_file_path = sys.argv[1]
    # 0. 全局变量与配置
    # 1. 创建保存策略的类
    policy_save_path = os.path.join('.', 'for_code_running', 'policy_store')
    tmp_path = os.path.join('.', 'for_code_running', 'tmp')
    policy_store_module = PolicyStoreModule(policy_save_path, tmp_path)
    # 2. 载入测试用策略
    set_database_by_policy_file(policy_store_module, policy_file_path)
    # 3. 启动
    start_access_control(policy_store_module)
